﻿var grid, cbProgress;


//初始化表格
function InitGrid() {
    var ord_id = $.trim($("#txtOrdSubjectCode").attr("value")); 
    var CheckTimeS = $('#CheckTimeS').datetimebox('getValue');
    var CheckTimeE = $('#CheckTimeE').datetimebox('getValue');
    grid = $('#tab_list').datagrid({
        name: 'tbl_data',
        url: '/PurchaseSum/Query',
        title: '采购对账单汇总列表',
        queryParams: {
            OrderNoOrGoodsCode: ord_id, 
            CheckTimeS: CheckTimeS,
            CheckTimeE: CheckTimeE
        },
        //width: 815,
        height: 730,
        //border : false,
        //fit: false,
        fitColumns: false,
        //nowrap: true,
        rownumbers: true,
        showFooter: true,
        //loadMsg: '正在加载信息...',
        //frozen: true,
        //sortName: "CODE", //排序设置
        singleSelect: true,
        //pagination: true,
        //pageSize: 5,
        //pageNumber: 1,
        //pageList: [5,10, 20, 30, 40, 50],
        idField: 'SheetID',
        columns: [[
        //{ field: 'ck', checkbox: true },
                    //{ field: 'GoodsID', title: '商品ID', hidden: true },
                    { field: 'SheetID', title: '采购进/退单号', width: 110, align: 'center', sortable: true },
                    { field: 'OrderType', title: '单据类型', width: 110, align: 'center', sortable: true },
                    { field: 'PayTypeName', title: '结算方式', width: 120, align: 'center', sortable: true },
                    { field: 'TotalQty', title: '总数量', width: 70, align: 'center', sortable: true },
                    { field: 'TotalCostValue', title: '总金额', width: 70, align: 'center', sortable: true },
                    { field: 'TotalCostTaxValue', title: '总税额', width: 70, align: 'center', sortable: true },
                    //{ field: 'Editor', title: '业务员', width: 80, align: 'center', sortable: true },
                    { field: 'CheckDate', title: '下单时间', width: 80, align: 'center', sortable: true, formatter: ChangeDateFormat },
                    { field: 'Flag', title: '订单状态', width: 80, align: 'center', sortable: true, formatter: formatflag }, 
                    { field: 'VenderName', title: '供应商', width: 150, align: 'center', sortable: true } 
                     
        ]],
        pagination: true,
        pageSize: 20,
        pageNumber: 1,
        pageList: [10, 20, 30, 40, 50],
        rownumbers: true, //行号
        onSortColumn: function (sort, order) {
            grid.datagrid('reload');
        }, 
        
    });
    //清空选择
    //grid.datagrid('clearSelections');
}

function formatflag(val) {
    if (val != null) {
        if (val == 20) {
            return "待处理";
        }
        if (val == 40) {
            return "在执行";
        }
        if (val == 100) {
            return "完结";
        }
        if (val == 90) {
            return "已审核";
        }
    }
}
//导出数据
//function ExporterExcel() {
//    var form = $('#frmPurchaseInOutSum');
//    var rows = $(".pagination-page-list option:selected").text();
//    var page = $("input[size='2']").val();
//    form.form('submit', {
//        url: '@Url.Content("~/PurchaseSum/ExportExcel")' + '?page=' + page + '&rows=' + rows,
//        success: function (data) {
//            eval('data=' + data);
//            if (data.success) {
//                InitGrid();
//            } else {
//                $.messager.alert('错误', data.msg, 'error');
//            }
//            //$("#txtOrdSubjectCode").val("");
//        }
//    });
//}

function ChangeDateFormat(val) {
    if (val != null) {
        var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
        //默认时间0001/01/01设置为空
        if (date.getFullYear() == "1")
            return "";
        //月份为0-11，所以+1，月份小于10时补个0
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        return date.getFullYear() + "-" + month + "-" + currentDate;
    }

    return "";
}

 
